from rest_framework.permissions import IsAdminUser
from rest_framework.viewsets import ModelViewSet
from goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from meiduo_admin.serializers.channel import GoodsChannelSerializer, GoodsChannelGroupSerializer
from meiduo_admin.utils import PageNum


class ChannelView(ModelViewSet):
    serializer_class = GoodsChannelSerializer
    queryset = GoodsChannel.objects.all()
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

class GoodsChannelGroupView(ModelViewSet):
    serializer_class = GoodsChannelGroupSerializer
    queryset = GoodsChannelGroup.objects.all()
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

class CategoriesView(ModelViewSet):
    serializer_class = GoodsChannelGroupSerializer
    queryset = GoodsCategory.objects.filter(parent=None)
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

